package com.koron.order.risk.riskDuty.service.impl;


import cn.hutool.core.collection.CollUtil;
import com.koron.order.risk.riskDuty.bean.po.LineRiskDutyPosition;
import com.koron.order.risk.riskDuty.mapper.LineRiskDutyPositionMapper;
import com.koron.order.risk.riskDuty.service.LineRiskDutyPositionService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 看护值守巡视位置信息(LineRiskDutyPosition)表服务实现类
 *
 * @author jzp
 * @since 2022-12-28 17:03:12
 */
@Service
public class LineRiskDutyPositionServiceImpl implements LineRiskDutyPositionService {

    /**
     * 通过ID查询单条数据
     *
     */
    @Override
    @TaskAnnotation("getById")
    public LineRiskDutyPosition getById(SessionFactory factory, String id) {
        LineRiskDutyPositionMapper mapper = factory.getMapper(LineRiskDutyPositionMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     *
     */
    @Override
    @TaskAnnotation("list")
    public List<LineRiskDutyPosition> list(SessionFactory factory, LineRiskDutyPosition lineRiskDutyPosition) {
        LineRiskDutyPositionMapper mapper = factory.getMapper(LineRiskDutyPositionMapper.class);
        return mapper.selectList(lineRiskDutyPosition);
    }

    @Override
    @TaskAnnotation("list")
    public List<LineRiskDutyPosition> listByPathId(SessionFactory factory, String pathId) {
        LineRiskDutyPosition lineRiskDutyPosition = new LineRiskDutyPosition();
        lineRiskDutyPosition.setPathId(pathId);
        return list(factory, lineRiskDutyPosition);
    }

    /**
     * 新增数据
     *
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, LineRiskDutyPosition lineRiskDutyPosition) {
        LineRiskDutyPositionMapper mapper = factory.getMapper(LineRiskDutyPositionMapper.class);
        return mapper.insertOrUpdate(lineRiskDutyPosition) > 0;
    }

    @Override
    @TaskAnnotation("saveBatch")
    public boolean saveBatch(SessionFactory factory, List<LineRiskDutyPosition> lineRiskDutyPositionList) {
        if (CollUtil.isEmpty(lineRiskDutyPositionList)) {
            return false;
        }
        LineRiskDutyPositionMapper mapper = factory.getMapper(LineRiskDutyPositionMapper.class);
        return mapper.insertOrUpdateBatch(lineRiskDutyPositionList) > 0;
    }

    /**
     * 修改数据
     *
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, LineRiskDutyPosition lineRiskDutyPosition) {
        LineRiskDutyPositionMapper mapper = factory.getMapper(LineRiskDutyPositionMapper.class);
        return mapper.update(lineRiskDutyPosition) > 0;
    }

    /**
     * 通过主键删除数据
     *
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        LineRiskDutyPositionMapper mapper = factory.getMapper(LineRiskDutyPositionMapper.class);
        return mapper.hidden(id) > 0;
    }

    @Override
    @TaskAnnotation("removeByPathId")
    public boolean removeByPathId(SessionFactory factory, String pathId) {
        LineRiskDutyPositionMapper mapper = factory.getMapper(LineRiskDutyPositionMapper.class);
        return mapper.removeByPathId(pathId) > 0;
    }
}
